﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Magnet.Engine.Physics;
using Magnet;

namespace Magnet.Engine.Entities
{
    public class Debris : Entity
    {
        Viewport viewport = MagnetGame.Graphics.GraphicsDevice.Viewport;

        public Debris(Vector2 position)
            : base(position, new Vector2(64,64), "ToggleMagnetN")
        {
        }

        public override void Update(float delta)
        {
            WallCollision();
            Collisions();
            base.Update(delta);
        }

        public void Collisions()
        {
            List<Arbiter> Arbiter = World.GetRelevantCollisions(this);

            foreach(Arbiter a in Arbiter)
            {
                Entity e = a.GetOtherEntity(this);
                if(e is Magnet)
                {
                        //Vector2.Reflect();
                }
            }
        }

        public void WallCollision()
        {
            float maxX = 912 - this.size.X;
            float maxY = 681 - this.size.Y;

            if (this.position.X > maxX)
            {
                this.velocity = Vector2.Reflect(this.velocity, new Vector2(1, 0));
            }
            else if (this.position.X < 125)
            {
                this.velocity = Vector2.Reflect(this.velocity, new Vector2(-1, 0));
            }

            if (this.position.Y > maxY)
            {
                this.velocity = Vector2.Reflect(this.velocity, new Vector2(0, 1));
            }
            else if (this.position.Y < 84)
            {
                this.velocity = Vector2.Reflect(this.velocity, new Vector2(0, -1));
            }
        }
    }
}
